
import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/chats'
  },
  {
    path: '/chats',
    name: 'Chats',
    component: () => import('@/views/ChatsView.vue'),
    meta: { title: '微信' }
  },
  {
    path: '/chat/:id',
    name: 'Chat',
    component: () => import('@/views/ChatView.vue'),
    meta: { title: '聊天' }
  },
  {
    path: '/contacts',
    name: 'Contacts',
    component: () => import('@/views/ContactsView.vue'),
    meta: { title: '通讯录' }
  },
  {
    path: '/discover',
    name: 'Discover',
    component: () => import('@/views/DiscoverView.vue'),
    meta: { title: '发现' }
  },
  {
    path: '/profile',
    name: 'Profile',
    component: () => import('@/views/ProfileView.vue'),
    meta: { title: '我' }
  },
  {
    path: '/moments',
    name: 'Moments',
    component: () => import('@/views/MomentsView.vue'),
    meta: { title: '朋友圈' }
  },
  {
    path: '/contact-detail/:id',
    name: 'ContactDetail',
    component: () => import('@/views/ContactDetailView.vue'),
    meta: { title: '详细资料' }
  },
  {
    path: '/qrcode',
    name: 'QRCode',
    component: () => import('@/views/QRCodeView.vue'),
    meta: { title: '二维码名片' }
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title as string || '微信'
  next()
})

export default router
